//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package order.util;

import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public final class MD5SHA256Util {
    private static final Logger log = LoggerFactory.getLogger(MD5SHA256Util.class);
    private static final String UTF8 = "UTF-8";
    private static final String ALGORITHM_SHA1 = "SHA-1";
    private static final String ALGORITHM_SHA256 = "SHA-256";
    private static final String ALGORITHM_MD5 = "MD5";

    public MD5SHA256Util() {
    }

    private static String encrypt(String orignal, String algorithm) {
        MessageDigest md = null;

        try {
            md = MessageDigest.getInstance(algorithm);
        } catch (NoSuchAlgorithmException var7) {
            log.error("找不到对应的算法", var7);
        }

        if (null != md) {
            try {
                byte[] origBytes = orignal.getBytes("UTF-8");
                md.update(origBytes);
                byte[] digestRes = md.digest();
                String resultString = byteToHexString(digestRes);
                return resultString;
            } catch (UnsupportedEncodingException var6) {
                log.error("使用算法加密失败", var6);
                return null;
            }
        } else {
            return null;
        }
    }

    private static String byteToHexString(byte[] origBytes) {
        StringBuilder hexString = new StringBuilder();

        for(int i = 0; i < origBytes.length; ++i) {
            String tempStr = Integer.toHexString(origBytes[i] & 255);
            if (tempStr.length() == 1) {
                hexString.append("0");
            }

            hexString.append(tempStr);
        }

        return hexString.toString();
    }

    public static String sha1(String str) {
        return encrypt(str, "SHA-1");
    }

    public static String sha256(String str) {
        return encrypt(str, "SHA-256");
    }

    public static String md5(String str) {
        return encrypt(str, "MD5");
    }
}
